﻿using System;
using System.Web.UI;

using Model;
using Model.Components;

namespace FrameWork.web.Manager.Module.Tousu.T_Web
{
    public partial class Exp : System.Web.UI.Page
    {
        Int32 IDX = (Int32)Common.sink("IDX", MethodType.Get, 10, 0, DataType.Int);
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
                Expword();
            }
        }

        private void BindData()
        {
            T_WebEntity ut = BusinessFacadeModel.T_WebDisp(IDX);
            TID_Disp.Text = ut.TID.ToString();
            TName_Disp.Text = ut.TName.ToString();
            TNo_Disp.Text = ut.TNo.ToString();
            TPhone_Disp.Text = ut.TPhone.ToString();
            TGroup_Disp.Text = ut.TGroup.ToString();
            TBGName_Disp.Text = ut.TBGName.ToString();
            TBAddress_Disp.Text = ut.TBAddress.ToString();
            TTtle_Disp.Text = ut.TTtle.ToString();
            TContent_Disp.Text = ut.TContent.ToString();
        }

        private void Expword()
        {
            System.IO.StringWriter SW = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter HTW = new System.Web.UI.HtmlTextWriter(SW);
            Page.RenderControl(HTW);
            //Page为要导出的对象,当前是Page,如果是DataGrid,DataList等都可以
            Response.Buffer = true;
            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.ContentType = "Response.ContentType";
            //Response.ContentType是输出流的 HTTP MIME 类型
            //Response.ContentType      --- word文件
            //application/vnd.ms-excel --- excel文件
            //
            Response.Charset = "utf-8";
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
            Response.AddHeader("Content-Disposition", "attachment;filename=XXX.doc");
            //attachment --- 作为附件下载
            //inline --- 在线打开
            //filename如过是中文,则可以用HttpUtility.UrlEncode(fileName,System.Text.Encoding.UTF8)
            //进行进行编码,以解决文件名乱码的问题
            Response.Write(SW.ToString());
            Response.Flush();
            Response.Close();
        }
    }
}